package com.sykj.cloud.activity.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.sykj.cloud.common.log.enums.LogUserType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sykj.cloud.common.log.annotation.Log;
import com.sykj.cloud.common.security.annotation.PreAuthorize;
import com.sykj.cloud.activity.domain.ActivitySession;
import com.sykj.cloud.activity.service.IActivitySessionService;
import com.sykj.cloud.common.core.web.controller.BaseController;
import com.sykj.cloud.common.core.web.domain.AjaxResult;
import com.sykj.cloud.common.core.utils.poi.ExcelUtil;
import com.sykj.cloud.common.core.web.page.TableDataInfo;

/**
 * 活动场次Controller
 *
 * @author mr.will
 * @date 2021-04-01
 */
@RestController
@RequestMapping("/session")
public class ActivitySessionController extends BaseController
{
    @Autowired
    private IActivitySessionService activitySessionService;

    /**
     * 新增活动场次
     */
    @PreAuthorize(hasPermi = "activity:session:add")
    @Log(title = "活动场次", logUserType = LogUserType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivitySession activitySession)
    {
        return toAjax(activitySessionService.insertActivitySession(activitySession));
    }

    /**
     * 修改活动场次
     */
    @PreAuthorize(hasPermi = "activity:session:edit")
    @Log(title = "活动场次", logUserType = LogUserType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivitySession activitySession)
    {
        return toAjax(activitySessionService.updateActivitySession(activitySession));
    }

    /**
     * 删除活动场次
     */
    @PreAuthorize(hasPermi = "activity:session:remove")
    @Log(title = "活动场次", logUserType = LogUserType.DELETE)
    @DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(activitySessionService.deleteActivitySessionByIds(guids));
    }

    /**
     * 获取活动场次详细信息
     */
    @PreAuthorize(hasPermi = "activity:session:query")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(activitySessionService.getActivitySessionById(guid));
    }

    /**
     * 导出活动场次列表
     */
    @PreAuthorize(hasPermi = "activity:session:export")
    @Log(title = "活动场次", logUserType = LogUserType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivitySession activitySession) throws IOException
    {
        List<ActivitySession> list = activitySessionService.listActivitySessions(activitySession);
        ExcelUtil<ActivitySession> util = new ExcelUtil<ActivitySession>(ActivitySession.class);
        util.exportExcel(response, list, "session");
    }

    /**
    * 查询活动场次列表
    */
    @PreAuthorize(hasPermi = "activity:session:list")
    @GetMapping("/list")
        public TableDataInfo list(ActivitySession activitySession)
    {
        startPage();
        List<ActivitySession> list = activitySessionService.listActivitySessions(activitySession);
        return getDataTable(list);
    }
    }
